home *** CD-ROM | disk | FTP | other *** search
- <XST Filename='send.xst'
- Description='Send an AddressRecord from the Pilot database to someone.'
- Author='David Ball'
- Version='2.0'
- Date='8 April 1999'
- Copyright='© 1999 DecisionSoft Limited'
- XMLscript='1.0'
- Ref='send'
- debug=''
- __maxCR="2"
- ><_if test=" \ENV\REQUEST_METHOD.__exists" >Content-type: text/html
-
- </_if>
-
- <!--
- We need the "Content-type: text/html" to be on the first output
- line followed by two carriage returns, if we're running in cgi
-
- Note the 'double backslash' used instead of the single backslash. Always
- use double backslash when describing DOS/Windows directory paths.
- -->
-
- <!--
- YOU NEED TO CONFIGURE THESE
- -->
- # $\.appsRoot := "..\\pilot\\" #
- # $\.datName := "sample.dat" #
-
- <!--
- If we're coming in from the command line, arguments with spaces in
- will have quotes around them, which we don't want (because DOS batch
- files are lame). So we need to get rid of them...
- -->
-
- <_if test="\ENV\FIRSTNAME.__exists">
- <then>
- <barney __mode="hide">
- <fred __maxCR="0"><_filter find='\"' replace=''># \ENV\FIRSTNAME #</_filter></fred>
- </barney>
- # \ENV\FIRSTNAME := $barney\fred #
- </then>
- </_if>
-
-
- <!--
- Set up our hostname
- -->
-
- <_if test=" \CGI\hostname.__exists">
- <then> # $\.hostname := \CGI\hostname # </then>
- <else>
- <_if test="\ENV\HOSTNAME.__exists">
- <then> # $\.hostname := \ENV\HOSTNAME # </then>
- <else>
- <_if test="\ENV\COMPUTERNAME.__exists">
- <then> # $\.hostname := \ENV\COMPUTERNAME # </then>
- <else>
- <_if test="\ENV\USERDOMAIN.__exists">
- <then> # $\.hostname := \ENV\USERDOMAIN # </then>
- <else> # $\.hostname := "localhost" # </else>
- </_if>
- </else>
- </_if>
- </else>
- </_if>
- </else>
- </_if>
-
- # $.sn := "0" #
- # $.fn := "0" #
-
- <_if test="not(\CGI\surname.__exists) and ( \ENV\SURNAME.__exists)" >
- # \CGI\surname := \ENV\SURNAME #
- </_if>
-
- <_if test="not(\CGI\firstname.__exists) and ( \ENV\FIRSTNAME.__exists)" >
- # \CGI\firstname := \ENV\FIRSTNAME #
- </_if>
-
- <_if test="not(\CGI\email.__exists) and ( \ENV\EMAIL.__exists)" >
- # \CGI\email := \ENV\EMAIL #
- </_if>
-
- <_if test="not(\CGI\mailserver.__exists) and ( \ENV\MAILSERVER.__exists)" >
- # \CGI\mailserver := \ENV\MAILSERVER #
- </_if>
-
- <_if test="not(\CGI\rcpt.__exists) and ( \ENV\RCPT.__exists)" >
- # \CGI\rcpt := \ENV\RCPT #
- </_if>
-
- <_if test=" \ENV\REQUEST_METHOD.__exists" >
- <then> # $\.context := "cgi" # </then>
- <else> # $\.context := "cmdline" # </else>
- </_if>
-
- <_if test="\CGI\surname.__exists"># $.sn := 1 #</_if>
- <_if test="\CGI\firstname.__exists"># $.fn := 1 #</_if>
-
- <_if>
-
- <!--
- Defaults used for debugging
- -->
- # \CGI\rcpt := "support@xmlscript.org" #
- # \CGI\mailserver := "mail1.best.com" #
- # \CGI\firstname := "William" # # $.fn := 1 #
- # \CGI\surname := "Clinton" # # $.sn := 1 #
- # \CGI\email := "test-send@xmlscript.org" #
- </_if>
-
- <!--
- Define the system command
- -->
-
- # $\.cmd := $\.appsRoot 'loadbook ' $\.appsRoot $\.datName #
- # $\.sysCmd := $\.cmd '> c:\\temp\\CGItmp.txt' #
-
-
- <!--
- The system command is piped to file to make it work with httpd.
- -->
-
- <_eval result="data">
- <_filter find='\#' replace='' >
- <Pilot>
- <_system command="# $\.sysCmd #"/>
- <_echo file="c:\temp\CGItmp.txt" />
- </Pilot>
- </_filter>
- </_eval>
-
- <_if test="0">
- Debug information: incoming data -# \Pilot #-
- </_if>
-
-
-
- <!--
- Define the template we're going to run
- -->
-
- <_template name="SendMail">
-
- <_socket host="# \CGI\mailserver #" port="25" store="irrel" timeout="180">
-
- <read_to>
- </read_to>
- <write>HELO # $\.hostname #
- </write>
- <read_to>
- </read_to>
- <write>MAIL FROM: # \CGI\email #
- </write>
- <read_to>
- </read_to>
- <write>RCPT TO: # \CGI\rcpt #
- </write>
- <read_to>
- </read_to>
- <write>DATA
- </write>
- <read_to>
- </read_to>
- <write>From: # \CGI\email #
- To: # \CGI\rcpt #
- Subject: XML AddressRecord for # \CGI\firstname # # \CGI\surname #.
-
- <_foreach object="AddressRecord" __maxCR="2">
- <_if test="not($.sn)"># \CGI\surname := LastName #</_if>
- <_if test="not($.fn)"># \CGI\firstname := FirstName #</_if>
- <_if test="(LastName == \CGI\surname) and (FirstName == \CGI\firstname)">
- <then>
- # .__object #
-
- </then>
- </_if>
- </_foreach>
- .
- </write>
- <read_to>
- </read_to>
- <write>QUIT
- </write>
- <close />
-
- </_socket>
-
- <!--
- This is not foolproof, but it is a quick look to see
- if we succeeded in sending the mail
- -->
-
- <_if test="(irrel\data[3] == '')">
- <then># $\.msg := 'X-Tract: connection timed out.'#</then>
- <else># $\.msg := 'X-Tract: mail sent successfully.'#</else>
- </_if>
-
- <_if test="$.context == cgi">
- <then>
- <HTML>
- <HEAD><TITLE>Xtract Mail Report</TITLE></HEAD>
- <BODY BGCOLOR="ffffff">
- <H1 ALIGN="Left"># $.msg #</H1>
- </BODY>
- </HTML>
- </then>
- <else># $.msg #</else>
- </_if>
-
- </_template>
-
- <!--
- Tie the template to the data
- -->
-
- <_method object="Pilot" template="SendMail" />
-
- <!--
- Process the data
- -->
-
- <_if test="(\CGI\rcpt.__exists) and (\CGI\email.__exists) and (\CGI\mailserver.__exists)">
- <then>
- <_process object="\Pilot" />
- </then>
- <else>
- <_if test="$.context == cgi">
- <then>
- <HTML>
- <HEAD><TITLE>Xtract Mail Report</TITLE></HEAD>
- <BODY BGCOLOR="ffffff">
- <H1 ALIGN="Left">X-Tract: mail not Sent.</H1>
- </BODY>
- </HTML>
- </then>
- <else>
- X-Tract: mail not Sent.
- </else>
- </_if>
- </else>
- </_if>
-
- </XST>
-